<?php
require_once('db.php');


$mod = $_POST['module'];
$view= $_POST['view'];

	$tmp = "";
	
	$p = json_decode(stripcslashes($_POST['json']),true);
	//Insert into tb_sales  :
	$sql = "INSERT INTO `tb_sales` (`bill_id`,`tot_item`,`total`,`tax`,`discount`,`grand_tot`,`paid`,`change`,`paidby`,`card_num`,`card_holder`,`customer`,`user_id`,`status`,`reff_id`) ";
	$sql.= " VALUES ('".$p['bill']['bill_id']."','".$p['bill']['tot_item']."','".$p['bill']['total']."','".$p['bill']['tax']."','".$p['bill']['discount']."','".$p['bill']['grand_tot']."','".$p['bill']['paid']."','".$p['bill']['change']."','".$p['bill']['paidby']."','".$p['bill']['card_num']."','".$p['bill']['card_holder']."','".$p['bill']['customer']."','".$p['bill']['userid']."','".$p['bill']['status']."','".$p['bill']['reff_id']."')";
	$result = @mysql_query($sql,$link);
	if (!$result) {
		die('Error: ' . @mysql_error($link));
	}
	
	$tmp .= $sql;
	
	//Insert into tb_order :
	$rows = $p['items'];
	
	foreach($rows as $i=>$r_value) {
		$sql = "";
		$sql = "INSERT INTO `tb_orders` (`order_id`,`prod_id`,`qty`,`customer`,`user_id`,`status`,`bill_num`,`order_tag`) ";
		$sql .= " VALUES (";
		foreach($r_value as $j=>$j_value) {
			$sql .= "'".$rows[$i][$j]."',";			
		}
		$sql = substr($sql,0,-1); 
		$sql .= ")";
		$result = @mysql_query($sql,$link);
		if (!$result) {
			die('Error: ' . @mysql_error($link));
		}
		$tmp .= $sql;
	}
	echo $p['bill']['bill_id'];
		
	mysql_close($link);
	
	

?>
